﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMS_Server;
using SMS_Server_Manager;

namespace SMS_Server_Manager.Forms
{
    public partial class ActionChooser : Form
    {
        public ActionChooser()
        {
            InitializeComponent();
        }

        private Form Sender;

        public System.Windows.Forms.DialogResult ViewDialog(Form sender)
        {
            Sender = sender;
            return this.ShowDialog(sender);
        }

        private void CancleButton_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void ContinueButton_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.DialogResult DR = System.Windows.Forms.DialogResult.Cancel;

            if (StaticResponse.Checked)
            {
                Forms.StaticResponse sr = new Forms.StaticResponse();
                Action_StaticResponse ASR = new Action_StaticResponse();
                ASR.ActionName = ((Function)((Mainform)Sender).FunctionList.SelectedItem).FunctionName;
                ASR.ActionFormat = ((Function)((Mainform)Sender).FunctionList.SelectedItem).ParamFormat;
                sr.Static_Response = ASR;
                DR = sr.ViewDialog(Sender);
            }
            if (SmsEmail.Checked)
            {
                Forms.SmsEmail se = new Forms.SmsEmail();
                Action_SMS_Email ASE = new Action_SMS_Email();
                ASE.ActionName = ((Function)((Mainform)Sender).FunctionList.SelectedItem).FunctionName;
                ASE.ActionFormat = ((Function)((Mainform)Sender).FunctionList.SelectedItem).ParamFormat;
                se.SMS_Email = ASE;
                DR = se.ViewDialog(Sender);
            }
            if (InsertInto.Checked)
            {
                Forms.InsertInto II = new Forms.InsertInto();
                Action_Insert AI = new Action_Insert();
                AI.ActionName = ((Function)((Mainform)Sender).FunctionList.SelectedItem).FunctionName;
                AI.ActionFormat = ((Function)((Mainform)Sender).FunctionList.SelectedItem).ParamFormat;
                II.Insert= AI;
                DR = II.ViewDialog(Sender);
            }
            if (SearchFrom.Checked)
            {
                Forms.SearchFrom sf = new Forms.SearchFrom();
                Action_Search AS = new Action_Search();
                AS.ActionName = ((Function)((Mainform)Sender).FunctionList.SelectedItem).FunctionName;
                AS.ActionFormat = ((Function)((Mainform)Sender).FunctionList.SelectedItem).ParamFormat;
                sf.Search = AS;
                DR = sf.ViewDialog(Sender);
            }
            if (ToTCP.Checked)
            {
                Forms.ToTCP TT = new Forms.ToTCP();
                Action_Forward2TCP AFTT= new Action_Forward2TCP();
                AFTT.ActionName = ((Function)((Mainform)Sender).FunctionList.SelectedItem).FunctionName;
                AFTT.ActionFormat = ((Function)((Mainform)Sender).FunctionList.SelectedItem).ParamFormat;
                TT.To_TCP = AFTT;
                DR = TT.ViewDialog(Sender);
            }
            if (ToHTTP.Checked)
            {
                Forms.ToHTTP TH = new Forms.ToHTTP();
                Action_Forward2HTTP AFTH = new Action_Forward2HTTP();
                AFTH.ActionName = ((Function)((Mainform)Sender).FunctionList.SelectedItem).FunctionName;
                AFTH.ActionFormat = ((Function)((Mainform)Sender).FunctionList.SelectedItem).ParamFormat;
                TH.To_HTTP = AFTH;
                DR = TH.ViewDialog(Sender);
            }
            if (DR == System.Windows.Forms.DialogResult.Cancel) return;
            else DialogResult = DR;
        }

        private void ActionChooser_Load(object sender, EventArgs e)
        {
            if (((Function)((Mainform)Sender).FunctionList.SelectedItem).FunctionName == "Unknown")
            {
                InsertInto.Enabled = false;
                SearchFrom.Enabled = false;
            }
        }

    }
}
